<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Download;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;

class DownloadController extends AdminController
{
    public bool $create = false;
    public bool $edit = false;
    public bool $delete = false;
    public bool $disable_actions = true;

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid(): Grid
    {
        return Grid::make(new Download(), function (Grid $grid) {
            $grid->model()->with(['user', 'material']);
            $grid->column('id');
            $grid->column('user.phone', trans('download.fields.user_id'));
            $grid->column('material.name', trans('download.fields.material_id'));
            $grid->column('created_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('user.phone', trans('download.fields.user_id'));
                $filter->like('material.name', trans('download.fields.material_id'));
            });
            $this->gridCommon($grid);
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Download(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('material_id');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Download(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('material_id');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
